/*
 * @Autor: zengy
 * @Date: 2021-07-28 13:53:41
 * @LastEditors: zengy
 * @LastEditTime: 2021-08-17 19:37:43
 * @Description: C#与H5通信
 * @FilePath: \Mics3.0_3DViewer_WEB\3DViewer\src\utils\wpf.js
 */
import store from '@/store';

/**
 * @description: 
* --- command 命令码  
* --- data 内容体
* --- message 消息
 * @return {*}
 */
window.wpfToH5 = function(result) {
    const { command, data }= JSON.parse(result);
    store.state.WPFEventBus.$emit(command, data);
}

/**
 * @description 通知客户端，h5加载完成，并传递h5的通用方法
 * @param {Object} sData 
 * @returns 
 */
async function setCallBack(sData = {}) {
    if (!window.CefSharp) return;
    await CefSharp.BindObjectAsync('wpfContentWindow');
    wpfContentWindow.setCallBack(null,JSON.stringify(sData));
}
/**
 * @description 传递数据给客户端
 * @param {Object} sData 
 * @returns 
 */
async function call(sData = {}) {
    if (!window.CefSharp) return;
    await CefSharp.BindObjectAsync('wpfContentWindow');
    wpfContentWindow.call(JSON.stringify(sData));
}


export default {
    install(App){
        App.config.globalProperties.setCallBack = setCallBack;
        App.config.globalProperties.call = call;
        App.config.globalProperties.wpfToH5 = wpfToH5;
    }
}
